<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/17
 * Time: 9:06
 */
class v5PHP {
    //运行框架
    static public function run(){
        //定义常量
        self::setConst();
        //加载核心文件
        self::loadFile();
        //创建常用目录
        self::createDir();
        //运行项目
        Application::run();
    }

    //创建常用目录
    static public function createDir(){
        if(is_dir(APP_PATH))return;
        $model = explode(',',MODULE_LIST);
        foreach($model as $m){
            $dirs = [
                APP_PATH,
                APP_PATH.$m.'/Controller',
                APP_PATH.$m.'/View',
                APP_PATH.$m.'/Model',
                APP_PATH.$m.'/Config',
                APP_PATH.$m.'/Lib',
            ];
            foreach($dirs as $dir){
                is_dir($dir) or mkdir($dir,0755,true);
            }
            //复制默认控制器
            copy(V5_PATH.'Tpl/IndexController.class.php',APP_PATH.$m.'/Controller/IndexController.class.php');
            //创建默认视图文件
            is_dir(APP_PATH.$m.'/View/Index') or mkdir(APP_PATH.$m.'/View/Index');
            copy(V5_PATH.'Tpl/View.html',APP_PATH.$m.'/View/Index/index.html');
        }
    }

    //定义常量
    static private function setConst(){
        define('V5_PATH',dirname(__FILE__).'/');
    }

    //加载文件
    static public function loadFile(){
        $files = [V5_PATH.'function.php',V5_PATH.'Application.class.php'];
        foreach($files as $file){
            if(is_file($file)){
                require($file);
            }
        }
    }
}

v5PHP::run();